import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['font.sans-serif'] = ['SimHei'] 

# 数据
companies = ['泰豪科技', '华丰股份']
operating_cash_flow = [-193195768.11, -12326434.41]
investing_cash_flow = [105944544.63, 120185918.57]
financing_cash_flow = [-8840690.25, 15791083.33]

# 设置柱状图的位置
x = np.arange(len(companies))
width = 0.2

# 创建图表
fig, ax = plt.subplots()

# 绘制柱状图
rects1 = ax.bar(x - width, operating_cash_flow, width, label='经营活动现金流量净额')
rects2 = ax.bar(x, investing_cash_flow, width, label='投资活动现金流量净额')
rects3 = ax.bar(x + width, financing_cash_flow, width, label='筹资活动现金流量净额')

# 添加文本标签、标题和自定义x轴刻度标签
ax.set_ylabel('现金流量净额 (元)')
ax.set_title('现金流量分析')
ax.set_xticks(x)
ax.set_xticklabels(companies)
ax.legend()

# 在柱状图上添加数值标签
def autolabel(rects):
    for rect in rects:
        height = rect.get_height()
        ax.annotate('{}'.format(height),
                    xy=(rect.get_x() + rect.get_width() / 2, height),
                    xytext=(0, 3),  # 3 points vertical offset
                    textcoords="offset points",
                    ha='center', va='bottom')

autolabel(rects1)
autolabel(rects2)
autolabel(rects3)

# 显示图表
plt.show()